<template>
    <div class="components-head">
        <van-nav-bar
	    left-text="返回"
	    left-arrow
        title="我的下级"
		@click-left="onClickLeft">
		<template #right>
			<div @click="toUser" class="nav-img"><img src="../assets/user.png" ></div>
		 </template>
	    </van-nav-bar>
        <!-- 列表区域 -->
	  <!-- 列表区域 -->
	  <van-list
		v-model="loading"
		:finished="finished"
		finished-text="没有更多了"
		@load="reLoadData"
		:immediate-check="false"
		offset="10"
		>
		<div class="level-list">
			<div class="level-item" v-for="item1 in levelerList" :key="item1.id">
				<div class="level-pic">
					{{item1.salesManNickName}}
				</div>
			</div>
		</div>
	  </van-list>
    </div>
</template>
<script>
import {levelList} from "@/api/user";
export default {
    data(){
        return{
            // 等级查询参数
            levelFrom:{
                pageNumber:1,
                pageSize:10,
                type:-1
            },
            
            loading: false,
      	    finished: false,
            levelerList:[]
        }
    },
    created(){
        this.loadData()
    },
    methods:{
        loadData(){
            const{levelFrom}=this
            levelList({
                pageNumber:levelFrom.pageNumber,
                pageSize:levelFrom.pageSize,
                type:levelFrom.type
                })
                .then(res=>{
                console.log(res)
                this.total=res.total
                this.levelerList=res.records
                this.levelerList = res.current === '1' ? res.records : [...this.levelerList, ...res.records];
				this.loading = false;
				// 如果
				if (this.levelerList.length >= res.total) {
					this.finished = true;		// 结束加载状态
				}else if(res.records.length>0){
					this.finished = false;
				}else if(res.records.length==0){
					this.finished = true;		
				}
            })
        },
        // 页码数++，重新加载数据
        reLoadData(){
            this.loading = true;
            const{levelFrom}=this
            levelFrom.pageNumber+=1
            this.loadData()
        },
        // 回到首页
        goHome(){
            this.$router.push({path:"/home"})
        },
        // 返回上一级
        onClickLeft(){
            this.$router.go(-1);
        },
		// 去用户信息
		toUser(){
			this.$router.push({path:"/user"})
		}
    }
}
</script>
<style lang="less" scoped>
// 顶部样式
/deep/.van-nav-bar__text{
	color: #333;
}
/deep/.van-nav-bar{
	.van-icon{
		color: #333;
	}
}
.nav-img{
	img{
		width: 0.34rem;
		height: 0.34rem;
	}
}
.title-logo{
	width: 1.92rem;
	height: 0.46rem;
}
// 列表
.level-item{
    height: 1.5rem;
}
.level-pic{
    font-size: 0.24rem;
}
</style>